package org.example.course.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.example.course.common.DataGridView;
import org.example.course.domain.Graduation;
import org.example.course.domain.User;
import org.example.course.dto.GraduationModel;
import org.example.course.mapper.GraduationMapper;
import org.example.course.service.GraduationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Classname GraduationServiceImpl
 * @Description 毕业要求
 * @Date 2020/5/8 15:30
 * @Created by
 */
@Service
public class GraduationServiceImpl implements GraduationService {
    @Autowired
    private GraduationMapper mapper;


    @Override
    public DataGridView findPage(GraduationModel graduationModel) {
        //分页插件 PageHelper
        PageHelper.startPage(graduationModel.getPage(), graduationModel.getLimit());
        List<Graduation> list = mapper.findAll(graduationModel);
        //PageHelper 获取分页信息
        PageInfo<Graduation> pageInfo = new PageInfo(list);

        return new DataGridView(pageInfo.getTotal(), list);
    }

    @Override
    public boolean create(Graduation graduation) {
        int msg = mapper.insert(graduation);
        return msg > 0;
    }

    @Override
    public boolean update(Graduation graduation) {
        int msg = mapper.updateByPrimaryKeySelective(graduation);
        return msg > 0;
    }

    @Override
    public boolean delete(String id) {
        int msg = mapper.deleteByPrimaryKey(Integer.valueOf(id));
        return msg > 0;
    }
}
